package rad.framework.mda.generator.template.conf;

import rad.framework.mda.generator.util.*;

public class PortalSetup
{
  protected static String nl;
  public static synchronized PortalSetup create(String lineSeparator)
  {
    nl = lineSeparator;
    PortalSetup result = new PortalSetup();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "// This bsh script setup the default content of the portal." + NL + "// It is called when the SessionFactoryBinder service has created a schema and needs to populate it" + NL + "import org.jboss.portal.common.util.Tools;" + NL + "import org.jboss.portal.identity.db.HibernateUserImpl;" + NL + "import org.jboss.portal.identity.db.HibernateRoleImpl;" + NL + "" + NL + "try" + NL + "{" + NL + "   session = SessionFactory.openSession();" + NL + "   tx = session.beginTransaction();" + NL + "" + NL + "   //" + NL + "   HibernateRoleImpl adminRole = new HibernateRoleImpl(\"Admin\", \"Administrators\");" + NL + "   HibernateRoleImpl userRole = new HibernateRoleImpl(\"User\", \"Users\");" + NL + "   HibernateRoleImpl role = new HibernateRoleImpl(\"Borrower\", \"Borrowers\");" + NL + "   session.save(role);" + NL + "   role = new HibernateRoleImpl(\"Broker\", \"Brokers\");" + NL + "   session.save(role);" + NL + "" + NL + "   //" + NL + "   HibernateUserImpl admin = new HibernateUserImpl(\"admin\");" + NL + "   admin.setPassword(Tools.md5AsHexString(\"admin\"));" + NL + "   admin.setRealEmail(\"admin@portal.com\");" + NL + "   admin.setViewRealEmail(true);" + NL + "   admin.setEnabled(true);" + NL + "" + NL + "   //" + NL + "   admin.getRoles().add(adminRole);" + NL + "   adminRole.getUsers().add(admin);" + NL + "" + NL + "   //" + NL + "   HibernateUserImpl user = new HibernateUserImpl(\"user\");" + NL + "   user.setPassword(Tools.md5AsHexString(\"user\"));" + NL + "   user.setRealEmail(\"user@portal.com\");" + NL + "   user.setViewRealEmail(true);" + NL + "   user.setEnabled(true);" + NL + "" + NL + "   //" + NL + "   user.getRoles().add(userRole);" + NL + "   userRole.getUsers().add(user);" + NL + "" + NL + "   //" + NL + "   session.save(adminRole);" + NL + "   session.save(userRole);" + NL + "   session.save(admin);" + NL + "   session.save(user);" + NL + "   tx.commit();" + NL + "}" + NL + "finally" + NL + "{" + NL + "   Tools.safeClose(session);" + NL + "}";
  protected final String TEXT_2 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    org.eclipse.uml2.uml.Model uml2Model = (org.eclipse.uml2.uml.Model) argument;
    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    return stringBuffer.toString();
  }
}
